package com.devo.icecream.ui.order

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import com.devo.icecream.R
import com.devo.icecream.ui.theme.Main
import com.devo.icecream.ui.theme.textGreyColor
import com.devo.icecream.ui.theme.yellow
import com.devo.icecream.ui.widget.AppButton

/**
 * 制作失败布局
 * @param price Int 错误码
 * @param onBack 返回主页
 */
@Composable
fun MakeFailLayout(price: Float, onBack: () -> Unit) {

    Column(
        modifier = Modifier
            .wrapContentHeight()
            .fillMaxWidth(),
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {

        Image(modifier = Modifier.size(40.dp), painter = painterResource(id = R.mipmap.time), contentDescription = "")

        Spacer(modifier = Modifier.height(34.dp))

        Text(
            buildAnnotatedString {
                append("￥")
                withStyle(style = SpanStyle(fontSize = MaterialTheme.typography.h1.fontSize)) {
                    append("%.02f".format(price))
                }
                append(", 退款中")
            },
            color = Main,
            fontSize = MaterialTheme.typography.h2.fontSize
        )
        Spacer(modifier = Modifier.height(24.dp))

        Text(text = "Oops,小料有点不够了！这杯赠送给您！", style = MaterialTheme.typography.h1)

        Spacer(modifier = Modifier.height(24.dp))

        Text(
            buildAnnotatedString {
                withStyle(SpanStyle(color = yellow)) {
                    append("支付款项将原路退回，")
                }
                append("谢谢理解，下次早点来吧！")
            },
            fontSize = MaterialTheme.typography.body1.fontSize,
            color = textGreyColor,
        )

        Spacer(modifier = Modifier.height(54.dp))

        AppButton(text = "换个口味吧!") {
            onBack()
        }

    }
}